/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hydropowermangement.hibernate;

import java.util.LinkedList;
import java.util.List;
import net.sf.cglib.proxy.Factory;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author MinhLuan
 */
public class TestMangement {
    /**
     * Variables
     */
    private static SessionFactory _factory;
    
    public TestMangement() {
        _factory = HibernateUtil.getSessionFactory();
    }

    
    public List<Test> listTest() {
        // Variables
        Session session = _factory.getCurrentSession();
        Transaction t = session.beginTransaction();
        Criteria criteria = session.createCriteria(Test.class);
        List list = new LinkedList<>();
        
        try {
            list = criteria.list();
            t.commit();
        } catch(HibernateException e) {
            t.rollback();
            throw e;
        }
        
        return list;
    }
}
